from time import sleep
from rk.rk702.Base import Base
from selenium.webdriver.common.by import By

class Page(Base):
    # 定位器
    login_loc = (By.LINK_TEXT,'登录')
    username_loc = (By.NAME,'username')
    password_loc = (By.NAME,'password')
    login_btn_loc = (By.CLASS_NAME,'finish-btn')
    search_loc = (By.XPATH,'//*[@id="searchForm"]/div[1]/input')
    search_btn_loc = (By.XPATH,'//*[@id="searchForm"]/div[2]/input')
    search_sp_loc = (By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/ul/li/div[1]/em/a')


    # 封装方法
    def login(self):
        self.click(self.login_loc)
    def login_user_pass(self):
        self.send_keys(self.username_loc,'18238680385')
        self.send_keys(self.password_loc,'123456')
    def login_btn(self):
        self.click(self.login_btn_loc)
    def search(self):
        self.send_keys(self.search_loc,'狗')
    def search_btn(self):
        self.click(self.search_btn_loc)

    # 业务逻辑
    def A3mall_luoji(self):
        self.login()
        sleep(1)
        self.login_user_pass()
        sleep(6)
        self.login_btn()
        sleep(5)
        self.search()
        sleep(1)
        self.search_btn()
        sleep(2)
        sp_name = self.find_element(self.search_sp_loc).text
        print(sp_name)
        assert '狗',str(sp_name)
